﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using MVCPets.Data;
using MVCPets.Models;
using MVCPets.Helpers;
namespace MVCPets.Controllers
{
  public class PetStatusManagementController : BaseController
  {
    #region Security
    protected override void Initialize(System.Web.Routing.RequestContext requestContext)
    {
      base.Initialize(requestContext);

      if (SessionHelper.UserRole <= RoleHelper.GetRoleValue("Administrator")) Return404();
    }
    #endregion

    #region Index
    [HttpGet]
    public ActionResult Index()
    {
      return View(PetStatusModel.GetStatuses());
    }
    #endregion

    #region Create
    [HttpGet]
    public ActionResult Create()
    {
      return View(new PetStatusModel());
    }

    [HttpPost]
    public ActionResult Create(PetStatusModel input)
    {
      if(input.Save()) return RedirectToAction("Index");
      else return View();
    }
    #endregion

    #region Edit
    [HttpGet]
    public ActionResult Edit(int id)
    {
      return View(new PetStatusModel(id));
    }

    [HttpPost]
    public ActionResult Edit(PetStatusModel input)
    {
      if(input.Save()) return RedirectToAction("Index");
      else return View();     
    }
    #endregion

    #region Delete
    [HttpGet]
    public ActionResult Delete(int id)
    {
      return View(new PetStatusModel(id));
    }

    [HttpPost]
    public ActionResult Delete(PetStatusModel input)
    {
      if(input.Delete()) return RedirectToAction("Index");
      else return View();
    }
    #endregion
  }
}
